#include <iostream>
#include <vector>

using namespace std;

const int MAX = 1024;

vector<int> intersection(vector<int> &nums1, vector<int> &nums2)
{
    if (nums1.empty() || nums2.empty())
        return {};

    int n1 = nums1.size();
    int n2 = nums2.size();
    int arr[MAX];   //标志存在某值
    vector<int> vi; //ans结果 ——>实现去重

    for (int i = 0; i < n1; i++)
        arr[nums1[i]] = 1; //记录标志

    for (int j = 0; j < n2; j++)
    {
        if (arr[nums2[j]] == 1)
        {
            vi.push_back(nums2[j]);
            arr[nums2[j]] = 0;  //标志位 使得 ans数组巧妙去重！
        }
    }
    return vi;
}


int main()
{
    int arr1[] = {4,7,9,7,6,7};
    int n1 = sizeof(arr1) / sizeof(arr1[0]);

    int arr2[] = {5,0,0,6,1,6,2,2,4};
    int n2 = sizeof(arr2) / sizeof(arr2[0]);

    vector<int> nums1(arr1, arr1 + n1);
    vector<int> nums2(arr2, arr2 + n2);

    vector<int> vi = intersection(nums1, nums2);
    for (auto i : vi)
        cout << i <<" ";
    return 0;
}